<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<head>
    <title>Title</title>
    <%@include file="../../common.jsp"%>
</head>
<body>
<h2>巡检员管理</h2>
<hr>
    <form class="layui-form" action="">
        <div class="layui-form-item">

            <div class="layui-inline">
                <label class="layui-form-label">巡检员名称:</label>
                <div class="layui-input-inline" style="width: 200px;">
                    <input id="inspectorName" type="text" name="inspectorName" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width: 100px;">
                    <button type="button" class="layui-btn layui-btn-normal" onclick="searchData();"><i class="layui-icon layui-icon-search"></i> 查询</button>
                </div>
            </div>

        </div>
    </form>
    <table class="layui-table" lay-data="{id:'poleTable',url:'${path}/inspector/list', page:true,toolbar:'#toolbarDemo',defaultToolbar: [],even: true}"
           lay-filter="poleTable">
        <thead>
        <tr>
            <th lay-data="{field:'id', width:80}">编号</th>
            <th lay-data="{templet:'#lineName'}">任务编码</th>
            <th lay-data="{field:'inspectorCode', width:180}">巡检员编码</th>
            <th lay-data="{field:'inspectorName'}">巡检员名称</th>
            <th lay-data="{field:'creationTime'}">创建时间</th>
            <th lay-data="{field:'createdBy'}">创建人</th>
            <th lay-data="{toolbar:'#barDemo'}">操作</th>
        </tr>
        </thead>
    </table>
    <script>

       function searchData(){
            layui.table.reload("poleTable",{
                page:{
                    curr : 1
                },
                where:{
                    "inspectorName":$("#inspectorName").val()
                }
            });
        }


       layui.use(["table"],function () {
           var table = layui.table;

           table.on('toolbar(poleTable)',function (obj) {
               var e = obj.event;
               switch (e) {
                   case "add":
                       $.get('${path}/inspector/form',function (str) {
                           layer.open({
                               type:1,
                               title:'添加消缺员',
                               area:'700px',
                               content: str,
                               btn: ['确定','取消'],
                               yes : function (index) {
                                   var params = $("#poleForm").serialize();
                                   $.post('${path}/inspector/add',params,function () {
                                       layer.close(index);
                                       layer.msg('添加成功!');
                                       table.reload('poleTable');
                                   });
                               }
                           });
                       });
                       break;
               }
           });

           //监听 行
           table.on("tool(poleTable)",function (obj) {
               var data = obj.data;
               if (obj.event == 'edit'){
                   $.get("${path}/inspector/form",function (str) {
                       layer.open({
                           type:1,
                           title:'修改消缺员',
                           content:str,
                           area:'700px',
                           skin:'layui-layer-molv',
                           btn:['确定','取消'],
                           success:function(){
                               $.get('${path}/inspector/get',{id:data.id},function (data) {
                                   //显示数据
                                   layui.form.val('poleForm',data);
                               });
                           },
                           yes : function (index) {
                               var params = $("#poleForm").serialize();
                               $.get("${path}/inspector/update",params,function (data) {
                                   layer.close(index);
                                   layer.msg('修改成功!');
                                   table.reload("poleTable");
                               });
                           }
                       });
                   });
               }else if(obj.event == 'del'){
                   layer.open({
                       time:0,
                       title:'友情提示',
                       content:'确定要删除吗？',
                       btn:['确定','取消'],
                       yes : function () {
                           $.post("${path}/inspector/del",{"id":data.id},function () {
                               layer.msg('删除成功！！！');
                               table.reload('poleTable');
                           });
                       }
                   })
               }
           })
       });
    </script>
    <script type="text/html" id="barDemo">
        <a href="javascript:void(0)" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></a>
        <a href="javascript:void(0)" lay-event="del"><i class="layui-icon layui-icon-delete"></i></a>
    </script>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon layui-icon-add-circle"></i> 添加</button>
        </div>
    </script>

    <script id="lineName" type="text/html">
        {{d.psInspectiontask_main == null ? '暂无任务' : d.psInspectiontask_main.inspectionTaskName}}
    </script>

</body>
</html>
